/**
 * Created by zdx on 2016/8/26 0026.
 */
define(["jquery","controller","validate"],function ($) {
    return {
        init:function () {
            var c = require("controller");
            $('.login-logo,.system_title').text('欢迎来到'+c.getTitle());
            /*$('input').on('focusin',function () {
                var target = $(this);
                $('.logininfo span').empty().text('请输入'+target.attr('placeholder'));
            });*/

            $('#loginForm').validate({
                messages: {
                    username: {
                        required: '请填写用户名'
                    },
                    password: {
                        required: '请填写密码'
                    }
                },
                submitHandler: function (form) {
                    var data = {'code': 'templete'},currect=true;
                    $('input').each(function(i){
                        data[this.name] = this.value;
                    });

                    $.ajax({
                        url:c.getValues('url')+'login',
                        type:'POST',
                        data:data,
                        success:function (result) {
                            if(result.err==0){
                                result.companys
                                if(result.companys&&typeof result.companys =="object"){
                                    result.companys=JSON.stringify(result.companys)
                                }
                                $.extend(localStorage,result);
                                window.location.href = 'index.html'
                            }else{
                                $('.logininfo span').empty().text(result.msg);
                            }
                        }
                    });
                }
            });

            $(window).on('keyup' ,function(e){
                if(e && e.keyCode==13){ // enter 键
                    $('#submit').click();
                }
            })
        }
    }

});
